package com.renjibo.myrecycleviewdemo;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.Random;

/**
 * 任继波
 * Created by Administrator on 2017/2/16.
 */

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.MyViewHolder> {


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_item,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.view.setBackgroundColor(Color.RED);
        LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) holder.view.getLayoutParams(); //取控件textView当前的布局参数
        linearParams.height = getNum();// 控件的高强制设成20
        linearParams.width = getNum();// 控件的宽强制设成30
        holder.view.setLayoutParams(linearParams); //使设置好的布局参数应用到控件</pre>
        //holder.linearLayout.setDividerPadding(100);
    }
public int getNum(){
    Random random=new Random();
    int i = random.nextInt(100) + 20;
    return i;
}
    @Override
    public int getItemCount() {
        return 120;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        View view;
        public MyViewHolder(View itemView) {
            super(itemView);
            view=itemView.findViewById(R.id.view);
        }
    }
}
